package sudoku_gameboard_structure;

import sudoku_gui.SudokuComponentsProperties;
import sudoku_properties.BasicSudokuParam;

/*********************************************************************
 * Class Cell
 * ~ Cell = a single cell
 * 1. perform and store parameters and functions
 *********************************************************************/
public class Cell {

    public Cell(){

        /* Cell setting 1 : set all the calculation to be possible */
        calcCell = new boolean[NUM_CELLS_IN_UNIT];
        for(int i=0; i<calcCell.length; i++){
            calcCell[i] = SudokuComponentsProperties.getIsTrue();
        }
        /* Cell setting 2 : default the cell value = zero */
        cellValue = 0;
        /* Cell setting 3 : default the cell is not a given cell*/
        isGiven = SudokuComponentsProperties.getIsFalse();
        isCorrectCell = SudokuComponentsProperties.getIsFalse();
    }

    public void setIsCorrectCell(boolean isCorrect){
        isCorrectCell = isCorrect;
    }

    public void setIsGiven(boolean isEnabled){
        isGiven = isEnabled;
    }

    public void setPossValue(int inputCellValue){
        int cellIndex = inputCellValue-1;
        calcCell[cellIndex] = SudokuComponentsProperties.getIsTrue();
    }
    public void setImpossValue(int inputCellValue){
        int cellIndex = inputCellValue-1;
        calcCell[cellIndex] = SudokuComponentsProperties.getIsFalse();
    }
    public boolean isPossValue(int inputCheckValue){
       int checkIndex = inputCheckValue - 1;
       return calcCell[checkIndex];
    }

    public boolean isCorrectCell(){
        return isCorrectCell;
    }
    public boolean isGiven(){
        return isGiven;
    }
    
    public int getNoOfPossValue()
    {
        int noOfPossValues = 0 ;
        for( int i = 0 ; i < calcCell.length ; ++i )
        {
            if( calcCell[i] )
            {
                ++noOfPossValues ;
            }
        }
        return noOfPossValues ;
    }

    public int[] getPossibleValues(){
        // no of possible values
        int numPossibleValues = getNoOfPossValue() ;
        // all the possible values
        int[] possValues = new int[numPossibleValues] ;
        int numPossValuesFound = 0;

        for(int i=0; i< calcCell.length; i++){
            if(calcCell[i]){
                possValues[numPossValuesFound] = i+1;
                numPossValuesFound++;
            }
        }
        return possValues ;
    }

    public void setCellValue(int inputCellValue){
        cellValue = inputCellValue;
    }

    public int getCellValue(){
        return cellValue;
    }
    /* local variables */
    private int NUM_CELLS_IN_UNIT = BasicSudokuParam.getNumCellsInUnit();

    /* store the value of cells  - user defined */
    private int cellValue;
    /* the cell use for the calculation progress - system defined */
    private boolean[] calcCell;
    /* determine type of cells - given or not */
    private boolean isGiven;
    /* determine if the cells solved successfully */
    private boolean isCorrectCell;

}
